//
//  GoShopCardTableViewController.m
//  GoodWayClient
//
//  Created by HuiDong on 15/12/8.
//  Copyright © 2015年 HuiDong. All rights reserved.
//

#import "GoShopCardTableViewController.h"
#import "GoShopCardTableViewCell.h"
#import "AllShop.h"
#import "WaitPayTableViewController.h"
#import "NothingInCard.h"

@interface GoShopCardTableViewController ()<changeViewControllerDelegate,deleteGoodDelegate>

@property (nonatomic, strong)NSMutableArray *array;
@property (nonatomic, strong)NSMutableArray *array1;
@property (nonatomic, assign)int b;

@end

@implementation GoShopCardTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (self.array.count == 0) {
        self.tableView.tableFooterView = nil;
        NothingInCard *nothing = [NothingInCard one];
        nothing.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
        [self.view addSubview:nothing];
    }else
    {
        AllShop *allshop = [AllShop footView];
        allshop.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 140);
        allshop.delegate = self;
        
        self.tableView.tableFooterView = allshop;
    }
}

//代理的跳转方法
- (void)changeViewController
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    WaitPayTableViewController *waitPay = [storyboard instantiateViewControllerWithIdentifier:@"WaitPayTableViewController"];
    [self presentViewController:waitPay animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//懒加载
- (NSMutableArray *)array
{
    if (!_array) {
        _array = [NSMutableArray arrayWithArray:@[@{@"image":@"logo",@"discri":@"啦啦啦啦啦了",@"amount":@"1000",@"peopleNumber":@"1028",@"number":@"1",@"money":@"￥290.00",@"collect":@"1"},@{@"image":@"logo",@"discri":@"啦啦啦啦啦了",@"amount":@"1000",@"peopleNumber":@"1028",@"number":@"1",@"money":@"￥290.00",@"collect":@"1"},@{@"image":@"logo",@"discri":@"啦啦啦啦啦了",@"amount":@"1000",@"peopleNumber":@"1028",@"number":@"1",@"money":@"￥290.00",@"collect":@"1"},@{@"image":@"logo",@"discri":@"啦啦啦啦啦了",@"amount":@"1000",@"peopleNumber":@"1028",@"number":@"1",@"money":@"￥290.00",@"collect":@"111"},@{@"image":@"logo",@"discri":@"啦啦啦啦啦了",@"amount":@"1000",@"peopleNumber":@"1028",@"number":@"1",@"money":@"￥290.00",@"collect":@"1"},@{@"image":@"logo",@"discri":@"啦啦啦啦啦了",@"amount":@"1000",@"peopleNumber":@"1028",@"number":@"1",@"money":@"￥290.00",@"collect":@"1"},@{@"image":@"logo",@"discri":@"啦啦啦啦啦了",@"amount":@"1000",@"peopleNumber":@"1028",@"number":@"1",@"money":@"￥290.00",@"collect":@"1"},@{@"image":@"logo",@"discri":@"啦啦啦啦啦了",@"amount":@"1000",@"peopleNumber":@"1028",@"number":@"1",@"money":@"￥290.00",@"collect":@"111"}]];
    }
    return _array;
}
- (NSMutableArray *)array1
{
    if (!_array1) {
        _array1 = [NSMutableArray array];
    }
    return _array1;
}

//数据源方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.array.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    GoShopCardTableViewCell *cell = [GoShopCardTableViewCell GoShopCardWithTableView:tableView];
    cell.dic = self.array[indexPath.row];
    cell.row = (int)indexPath.row;
    cell.delegate = self;
    if (self.b == 1) {
        cell.a = 1;
        [cell.selectBtn setBackgroundImage:[UIImage imageNamed:@"goodSelected.png"] forState:UIControlStateNormal];
    }else
    {
        cell.a = 0;
         [cell.selectBtn setBackgroundImage:[UIImage imageNamed:@"goodNotSelected.png"] forState:UIControlStateNormal];
    }
    
    return cell;
}

//设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 140;
}

//隐藏状态栏
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return YES;
}

- (void)delete:(int)number
{
    [self.array removeObjectAtIndex:number];
    [self.tableView reloadData];
    [self viewDidLoad];
}
- (void)selectedAdd:(int)number
{
    NSDictionary *dic = self.array[number];
    [self.array1 addObject:dic];
}
- (void)selectedPlus:(int)number
{
    NSDictionary *dic = self.array[number];
    [self.array1 removeObject:dic];
}
- (void)collectAdd:(int)number
{
    
}
- (void)collectPlus:(int)number
{
    
}
- (void)myselectAll
{
    self.b = 1;
    [self.tableView reloadData];
}
- (void)mynotselectAll
{
    self.b = 0;
    [self.tableView reloadData];
}


@end
